﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <!-- jsp文件头和头部 -->
    <%@ include file="../admin/top.jsp" %>

    <style>
        .li_style {
            list-style: none;
            margin: 0;
            padding: 0;
            padding-top: 20px;
            height: 50px;
            padding-left: 50px;
            float: left;
        }

        .ul_style {
            list-style: none;
            margin: 0;
            padding: 0;
            padding-top: 20px;
            height: 50px;
            padding-left: 50px;
        }
    </style>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <form action="">
                    <div style="width: 80%; padding-top: 50px; padding-left: 50px">
                        <div style="padding: 20px;border: solid 0.5px;box-shadow: 0 0 5px 3px rgba(209, 209, 255, 0.5);border-radius: 10px">
                            <div>
                                <label style="float:left;padding-right: 10px">
                                    <input name="importType" type="radio" value="0">
                                    <span class="lbl">单个录入</span>
                                </label>
                                <input type="text" name="imei" id="imei" placeholder="输入IMEI/MEID">
                                <br/>
                            </div>
                            <br/>
                            <div>
                                <label style="float:left;padding-right: 10px;">
                                    <input name="importType" type="radio" value="1" checked>
                                    <span class="lbl">批量录入</span>
                                </label>
                                <input type="file" name="file" id="file" onchange="changeFile()">
                                <br/>
                            </div>
                            <br/>
                        </div>
                        <ul class="ul_style" style="margin-left: -36px;">
                            <label class="li_style" style="margin-left: -50px;font-weight: bold">
                                <font color='red'>*</font>
                                选择渠道商:
                            </label>
                            <select class="form-control in-block" name="channelId" id="channelId"
                                    style="width: 20%;margin-left: 30px;margin-top: 15px;float: left;" onchange="updateDevModels()">
                                <option value="" selected> 请选择设备渠道</option>
                                <c:forEach items="${channels}" var="channel">
                                    <option value="${channel.id}">${channel.name}</option>
                                </c:forEach>
                            </select>

                            <select class="form-control in-block" name="devModelId" id="devModelId"
                                    style="width: 20%;margin-left: 30px;margin-top: 15px;float: left;">
                                <option value="" selected> 请选择设备型号</option>
                                <!-- 动态选项将在这里被添加 -->
                            </select>
                        </ul>
                        <ul class="ul_style" style="margin-left: -36px;">
                            <div style="margin-left: -14px; padding: 15px; float: left">
                                <input type="checkbox" name="canCheckPosition" value="1" checked>
                                <span class="lbl"> 渠道商查看设备位置</span>
                            </div>
                        </ul>
                        <ul class="ul_style" style="margin-left: -36px;">
                            <div style="margin-left: -14px; padding: 15px; float: left">
                                <span class="lbl">设备是否为RTOS模式：</span>
                                <input name="isRtosModule" type="radio" value="1">
                                <span class="lbl">是</span>
                                <input name="isRtosModule" type="radio" value="0" checked>
                                <span class="lbl">否</span>
                            </div>
                        </ul>
                        <ul class="ul_style" style="margin-left: -36px;">
                            <div style="margin-left: -14px; padding: 15px; float: left">
                                <span class="lbl">设备是否为新版微聊协议：</span>
                                <input name="isNewWechatProtocol" type="radio" value="1">
                                <span class="lbl">是</span>
                                <input name="isNewWechatProtocol" type="radio" value="0" checked>
                                <span class="lbl">否</span>
                            </div>
                        </ul>
                        <ul class="ul_style" style="margin-left: -36px;">
                            <label class="li_style" style="margin-left: -50px;font-weight: bold">
                                <%--<font color='red'>*</font>--%>
                                生产批次:
                            </label>
                            <div style="padding: 15px;float: left">
                                <input type="checkbox" name="ifHaveProductionBatch" value="1" checked disabled>
                                <span class="lbl">自动生成</span>
                            </div>
                        </ul>

                        <div style="font-size: 14px;color: red; white-space: pre-wrap">
                            <span id="msgHint"
                                  style="display: none;float: left;margin-right: 10px;width: 95%;white-space: normal;font-weight: bold"></span>
                        </div>
                        <br/>
                        <div style="margin-top: 30px;">
                            <input class="btn btn-primary" type="button" onclick="save()" value=确定 id="submitBut">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
    <i class="icon-double-angle-up icon-only"></i>
</a>
<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>

<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<!-- 引入 -->
<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
<script type="text/javascript">
    $(top.hangge());
</script>

</body>
</html>

<script type="text/javascript">
    $(function () {
        //下拉框
        $(".chzn-select").chosen();
        $(".chzn-select-deselect").chosen({allow_single_deselect: true});
    });

    $("#isWatchCustomFunction").change(function () {
        if (this.checked) {
            $("#shoudongpeizhi").css("display", "none");
        } else {
            $("#shoudongpeizhi").css("display", "block");
        }
    });
    // // 直接 选中 自动配置, 并且不可修改
    //
    // $("#isWatchCustomFunction")[0].checked = true;
    // $("#shoudongpeizhi").css("display", "none");

    $("#isOtherPT").change(function () {
        if (this.checked) {
            $("#selectDMPAccountDataId").css("display", "block");
        } else {
            $("#selectDMPAccountDataId").css("display", "none");
        }
    });

    //动态选择设备型号
    function updateDevModels() {
        var channelId = document.getElementById('channelId').value;
        var devModelSelect = document.getElementById('devModelId');
        // 清空当前的所有选项
        devModelSelect.innerHTML = '<option value="">请选择设备型号</option>';

        // 假设 devModels 是一个包含设备型号的数组
        // 遍历 devModels 并根据 channelId 过滤选项
        <c:forEach items="${devModels}" var="devModel">
            if ("${devModel.vender}" == channelId) {
                var option = document.createElement('option');
                option.value = '${devModel.id}';
                option.text = '${devModel.model}';
                devModelSelect.add(option);
            }
        </c:forEach>
    }

    //保存
    function save() {
        var formData = new FormData();
        var type = $("input[name='importType']:checked").val();
        if (type == 0) {//单个导入
            var imei = $("#imei").val();
            if (imei == "") {
                $("#imei").tips({
                    side: 3,
                    msg: '请输入imei号',
                    bg: '#AE81FF',
                    time: 2
                });
                $("#imei").focus();
                return false;
            }
            formData.append("imei", imei);
        } else if (type == 1) { //文件导入
            var fileObj = $('#file').get(0).files[0];
            if (!fileObj) {
                $("#file").tips({
                    side: 3,
                    msg: '请选择文件',
                    bg: '#AE81FF',
                    time: 2
                });
                $("#file").focus();
                return false;
            }
            formData.append("file", fileObj);
        } else {
            $("#type").tips({
                side: 3,
                msg: '请选择录入方式',
                bg: '#AE81FF',
                time: 2
            });
            $("#type").focus();
            return false;
        }
        formData.append("type", type);
        var channelId = $("#channelId").val();
        if (channelId == "") {
            $("#channelId").tips({
                side: 3,
                msg: '请选择渠道',
                bg: '#AE81FF',
                time: 2
            });
            $("#channelId").focus();
            return false;
        }
        formData.append("channelId", channelId);
        //选择 设备型号
        var devModelId = $("#devModelId").val();
        if (devModelId == "") {
            $("#devModelId").tips({
                side: 3,
                msg: '请选择设备型号',
                bg: '#AE81FF',
                time: 2
            });
            $("#devModelId").focus();
            return false;
        }
        formData.append("devModelId", devModelId);
        formData.append("ifHaveProductionBatch", 1);
        //设置设备的支持是否支持RTOS
        var isRtos = $("input[name='isRtosModule']:checked").val();
        formData.append("isRtosModule",isRtos);
        var isNewWechatProtocol = $("input[name='isNewWechatProtocol']:checked").val();
        formData.append("isNewWechatProtocol",isNewWechatProtocol);
        // var videoModelId = $("#videoModelId").val();
        // if (videoModelId) {
        //     formData.append("videoModelId", videoModelId);
        // }
        // var canCheckPosition = $("input[name='canCheckPosition']:checked").val();
        // if (canCheckPosition) {
        //     formData.append("canCheckPosition", canCheckPosition);
        // }
        // var ifHaveProductionBatch = $("input[name='ifHaveProductionBatch']:checked").val();
        // if (ifHaveProductionBatch) {
        //     formData.append("ifHaveProductionBatch", ifHaveProductionBatch);
        // }
        // var modules = "";
        // $("input[name='modules1']:checked").each(function () {
        //     modules += $(this).val();
        // });
        // var isWatchCustomFunction = $("input[name='isWatchCustomFunction']:checked").val();
        // if (isWatchCustomFunction) {
        //     formData.append("isWatchCustomFunction", isWatchCustomFunction);
        // } else {
        //     var ppmfmodules = $("input[name='ppmfmodules']:checked").val();
        //     if (ppmfmodules) {
        //         formData.append("ppmfmodules", ppmfmodules);
        //     }
        //     var telecom = $("input[name='telecom']:checked").val();
        //     if (telecom) {
        //         formData.append("telecom", telecom);
        //     }
        //     var dataFlow = $("input[name='dataFlow']:checked").val();
        //     if (dataFlow) {
        //         formData.append("dataFlow", dataFlow);
        //     }
        //     var costFlow = $("input[name='costFlow']:checked").val();
        //     if (costFlow) {
        //         formData.append("costFlow", costFlow);
        //     }
        //     var opdialswitch = $("input[name='opdialswitch']:checked").val();
        //     if (opdialswitch) {
        //         formData.append("opdialswitch", opdialswitch);
        //     }
        //     var watchStoreChannelId = $("#watchStoreChannelId").val();
        //     if (watchStoreChannelId) {
        //         formData.append("watchStoreChannelId", watchStoreChannelId);
        //         var watchStoreChannelName = $("#watchStoreChannelId option:selected").attr("data-disName");
        //         formData.append("watchStoreChannelName", watchStoreChannelName);
        //     }
        //     $("input[name='modules']:checked").each(function () {
        //         modules += $(this).val();
        //     });
        // }
        // if (modules) {
        //     formData.append("modules", modules);
        // }
        // var JuphoonPermanent = $("input[name='JuphoonPermanent']:checked").val();
        // if (JuphoonPermanent) {
        //     formData.append("JuphoonPermanent", JuphoonPermanent);
        // }
        // var JFvideolimit553 = $("input[name='JFvideolimit553']:checked").val();
        // if (JFvideolimit553) {
        //     formData.append("JFvideolimit553", JFvideolimit553);
        // }
        // var videoLimitStatus = $("input[name='videoLimitStatus']:checked").val();
        // if (videoLimitStatus) {
        //     formData.append("videoLimitStatus", videoLimitStatus);
        // }
        //
        // var dmpAccountId = $("#dmpAccountId").val();
        // if (dmpAccountId) {
        //     formData.append("dmpAccountId", dmpAccountId);
        // }

        if (type == 1) {
            $("#msgHint").css("display", "block");
            $("#msgHint").text("正在进行批量录入，请耐心等待！");
        }
        $("#submitBut").attr("disabled", true);
        $.ajax({
            type: "post",
            url: "/device/importDevice",
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                $("#submitBut").attr("disabled", false);
                $("#msgHint").css("display", "block");
                $("#msgHint").css("white-space", "pre-wrap");
                $("#msgHint").html(data.msg);
                if (type == 1) {
                    $("#file").val("");
                }
            }
        })
    }
    function changeFile() {
        $("#msgHint").css("display", "none");
    }
</script>
